import {defineStore} from 'pinia'
import axios from 'axios';
import { nanoid } from 'nanoid';
// export const useLoveStore = defineStore('love',{
//     //data
//     state(){
//         return {
//             talkList:JSON.parse(localStorage.getItem('talkList') as string )|| []
//         }
//     },
//     //methods
//     actions:{
//         async getLoveTalk_store(){
//             let {data:{content:title}} =  await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');
//             let obj = {id:nanoid(),title}
//             this.talkList.unshift(obj)
//         }
//     },
//     //computed
//     getters:{}
// })
import { reactive } from 'vue';
export const useLoveStore = defineStore('love',()=>{


    let talkList = reactive(JSON.parse(localStorage.getItem('talkList') as string )|| [])


    async function getLoveTalk_store(){
        let {data:{content:title}} =  await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');
        let obj = {id:nanoid(),title}
        talkList.unshift(obj)
    }

    return {talkList,getLoveTalk_store}
})